package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

import flc.ast.AppConfig;
import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.MoreRecAdapter;
import flc.ast.databinding.ActivityDanceDetailBinding;
import stark.common.api.StkResApi;
import stark.common.base.IReqRetCallback;
import stark.common.basic.event.EventStatProxy;
import stark.common.bean.StkResBean;

public class DanceDetailActivity extends BaseAc<ActivityDanceDetailBinding> {

    public static StkResBean stkResBean;
    private MoreRecAdapter recAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_dance_detail;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(this, mDataBinding.event5Container);

        mDataBinding.ivDanceDetailBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.rvRecommendList.setLayoutManager(new GridLayoutManager(mContext, 2));
        recAdapter = new MoreRecAdapter();
        mDataBinding.rvRecommendList.setAdapter(recAdapter);
        recAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        StkResBean bean = (StkResBean) adapter.getItem(position);
        DanceDetailActivity.stkResBean = bean;
        startActivity(DanceDetailActivity.class);
        finish();
    }

    @Override
    protected void initData() {
        mDataBinding.webView.loadUrl(stkResBean.getUrl());
        getData();
    }

    private void getData() {
        StkResApi.getTagResourceList(this, AppConfig.MORE_REC_DATA, StkResApi.createParamMap(0, 8), false, new IReqRetCallback<List<StkResBean>>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable List<StkResBean> result) {
                if (success) {
                    if (result != null && result.size() > 0) {
                        recAdapter.setList(result);
                    }
                }
            }
        });
    }

}